package com.LeeCode;

/**
 * 形成目标数组的子数组最少增加次数
 */

public class Code1526 {
    public static void main(String[] args) {
        int[] target = {1, 2, 3, 2, 1};
        System.out.println(new Code1526().minNumberOperations(target));
    }

    public int minNumberOperations(int[] target) {
        int ans = target[0];
        for (int i = 1; i < target.length; i++) {
            int diff = target[i] - target[i - 1];
            if (diff > 0) ans += diff;
        }
        return ans;
    }
}
